package flca.voicenav.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Helper class to maintain list of TracePt. It is basically an arraylist with some util methods.
 * Note to retrieve to most recent location, use last() !
 * @author robin
 *
 */
public class TracePoints
{
	private List<TracePt> tracePtList = new ArrayList<TracePt>();
	
	public void add(TracePt aTracePt) {
		aTracePt.setArrayIndex(tracePtList.size()-1);
		tracePtList.add(aTracePt);
	}
	
	/**
	 * return the start location
	 * @return
	 */
	public TracePt first() {
		if (size() > 0) {
			return tracePtList.get(0);
		} else {
			return null;
		}
	}

	/**
	 * return the most recent location
	 * @return
	 */
	public TracePt last() {
		if (size() > 0) {
			return tracePtList.get(size()-1);
		} else {
			return null;
		}
	}
	
	/**
	 * return the second most recent location
	 * @return
	 */
	public TracePt prev() {
		if (size() > 1) {
			return tracePtList.get(size()-2);
		} else {
			return last();
		}
	}
	
	public TracePt get(int aIndex) 
	{
		if (size() > 0 && aIndex < size()) {
			return tracePtList.get(aIndex);
		} else {
			return null;
		}
	}
	
	public int size() {
		return tracePtList.size();
	}
}	
